<!DOCTYPE html>
<html>
<head>
    {% if title %}
        <title>{{ title }} - ftp</title>
    {% else %}
        <title>ftp</title>
    {% endif %}
</head>
<body>
<div>
    ftp:
    <a href="/ftp/">主页</a>
    <a href="/ftp/{{ flashPath }}">刷新</a>
    <a href="/upload">上传</a>
    <a href="/upPath">向上</a>
    <a href="/prePath">后退</a>
    <a href="/nextPath">前进</a>
    <a href="/searchFile">搜索文件</a>
    <a href="/searchText">搜索文本</a>
{#    <a href="/clear">clear</a>#}
</div>
<hr>

{% with messages = get_flashed_messages() %}
    {% if messages %}
        <ul>
            {% for message in messages %}
                <li>{{ message }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endwith %}

{% if isUpload %}
    <script>
        function UpladFile() {
            // 获取文件对象
            var fileObj = document.getElementById("file").files[0];
            // 接收上传文件的后台地址
            var FileController = "/upload";
            // FormData 对象
            var form = new FormData();
            // 文件对象
            form.append("file", fileObj);
            // XMLHttpRequest 对象
            var xhr = new XMLHttpRequest();
            xhr.open("post", FileController, true);
            xhr.onload = function () {
                //   console.log("上传完成!");
            };
            xhr.upload.addEventListener("progress", progressFunction, false);
            xhr.send(form);
        }
        function progressFunction(evt) {
            var progressBar = document.getElementById("progressBar");
            var percentageDiv = document.getElementById("percentage");
            if (evt.lengthComputable) {
                progressBar.max = evt.total;
                progressBar.value = evt.loaded;
                percentageDiv.innerHTML = Math.round(evt.loaded / evt.total * 100) + "%";
            }
        }
    </script>
    <form action="/upload" method=post enctype=multipart/form-data>
        <input type=file id="file" name=浏览>
        <p>
            <input type=button onclick="UpladFile()" value=上传>
            <progress id="progressBar" value="0" max="100"></progress>
            <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
        </p>
    </form>
{% endif %}

{% if isSearchFile %}
    <form action="/searchFile" method="post">
        <label>
            <input type="text" name="search_text">
            <input type="submit" value="搜索" name="s_search_text">
            <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
        </label>
    </form>
{% endif %}

{% if isSearchText %}
    <form action="/searchText" method="post">
        <label>
            <input type="text" name="search_text">
            <input type="submit" value="搜索" name="s_search_text">
            <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
        </label>
    </form>
{% endif %}

{% if isCreateDir %}
    <form action="/createDir" method="post">
        <label>
            <input type="text" name="dirname">
            <input type="submit" name="s_dir_name">
            <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
        </label>
    </form>
{% endif %}

{% if isCreateFile %}
    <form action="/createFile" method="post">
        <label>
            请输入文本:
            <br>
            <textarea name="filetext"></textarea>
        </label>
        <br>
        <label>
            请输入文件名:
            <br>
            <input type="text" name="filename">
            <input type="submit" name="submit_file_name_text">
            <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
        </label>
    </form>
{% endif %}

{% if searchFileRes %}
    <ul>
        <li>开始搜索..</li>
        {% for filepath in  searchFileRes%}
            <li>
                <a target="" href="/ftp/{{ filepath }}">{{ filepath }}</a>
            </li>
        {% endfor %}
        <li>搜索完成!</li>
    </ul>
{% endif %}

{% if searchTextRes %}
    <ul>
        <li>开始搜索..</li>
        {% for filepath in  searchTextRes%}
            <li>
                <a target="" href="/ftp/{{ filepath }}">{{ filepath }}</a>
            </li>
        {% endfor %}
        <li>搜索完成!</li>
    </ul>
{% endif %}

<form>
    {% if dirList %}
        {% for filename in dirList %}
            <label>
                <input type="checkbox" value="{{ filename }}" name="{{ filename }}">
                <a target="" href=/ftp/{{ path }}{{ filename }}>{{ filename }}</a>
                <br>
            </label>
        {% endfor %}
    {% endif %}
    <br>

    {% if fileList %}
        {% for filename in fileList %}
            <label>
                <input type="checkbox" value="{{ filename }}" name="{{ filename }}">
                <a target="" href=/ftp/{{ path }}{{ filename }}>{{ filename }}</a>
                <br>
            </label>
        {% endfor %}
    {% endif %}
    <hr>

    <input type=submit value=新建文件夹 formaction="/createDir" formmethod="get" name="createDir">
    <input type=submit value=新建文件 formaction="/createFile" formmethod="get" name="createFile">
    {% if isCopy %}
        <input type=submit value=复制到... formaction="/paste" formmethod="post" name="copy">
        <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
    {% else %}
        <input type=submit value=复制 formaction="/copy" formmethod="post" name="copy">
    {% endif %}

    {% if isMov %}
        <input type=submit value=移动到... formaction="/paste" formmethod="post" name="mov">
        <input type=submit value=取消 formaction="/cancel" formmethod="post" name="cancel">
    {% else %}
        <input type=submit value=移动 formaction="/mov" formmethod="post" name="mov">
    {% endif %}

    <input type=submit value=删除 formaction="/del" formmethod="post" name="del">
</form>

</body>
</html>